using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VARDO
    {
        public DataRow Convert2ARDO(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryARDO(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AROMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AROAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["AROAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["AROAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["AROANSNR"] = " ".PadRight(0 ); 
         dwReturn["AROABRNR"] = " ".PadRight(0 ); 
         dwReturn["AROAENZL"] = " ".PadRight(0 ); 
         dwReturn["AROAENB"] = " ".PadRight(8 ); 
         dwReturn["AROAEND"] = " ".PadRight(0 ); 
         dwReturn["ARONEUB"] = " ".PadRight(8 ); 
         dwReturn["ARONEUD"] = " ".PadRight(0 ); 
         dwReturn["AROAUFSTA"] = " ".PadRight(1 ); 
         dwReturn["AROBDAT"] = " ".PadRight(0 ); 
         dwReturn["AROBZT"] = " ".PadRight(0 ); 
         dwReturn["AROREFNR"] = " ".PadRight(16 ); 
         dwReturn["AROPRIO"] = " ".PadRight(2 ); 
         dwReturn["ARODOSYS1"] = " ".PadRight(2 ); 
         dwReturn["ARODOEZT1"] = " ".PadRight(0 ); 
         dwReturn["ARODOSYS2"] = " ".PadRight(2 ); 
         dwReturn["ARODOEZT2"] = " ".PadRight(0 ); 
         dwReturn["ARODOSYS3"] = " ".PadRight(2 ); 
         dwReturn["ARODOEZT3"] = " ".PadRight(0 ); 
         dwReturn["AROBHNR"] = " ".PadRight(0 ); 
         dwReturn["AROFMGS"] = " ".PadRight(0 ); 
         dwReturn["AROFMGI"] = " ".PadRight(0 ); 
         dwReturn["AROWASMGI"] = " ".PadRight(0 ); 
         dwReturn["AROMTYP"] = " ".PadRight(8 ); 
         dwReturn["AROMNRKRS"] = " ".PadRight(2 ); 
         dwReturn["AROMLFDNR"] = " ".PadRight(4 ); 
         dwReturn["AROMPOS"] = " ".PadRight(2 ); 
         dwReturn["AROBDEMA"] = " ".PadRight(8 ); 
         dwReturn["AROAFOLGE"] = " ".PadRight(0 ); 
         dwReturn["AROAGANG"] = " ".PadRight(15 ); 
         dwReturn["ARODREZART"] = " ".PadRight(1 ); 
         dwReturn["ARODREZNR"] = " ".PadRight(10 ); 
         dwReturn["ARODREZST"] = " ".PadRight(1 ); 
         dwReturn["AROABRNR2"] = " ".PadRight(0 ); 
         dwReturn["AROART"] = " ".PadRight(20 ); 
         dwReturn["AROARTBEZ"] = " ".PadRight(40 ); 
         dwReturn["AROFARBE"] = " ".PadRight(10 ); 
         dwReturn["AROFARBEZ"] = " ".PadRight(20 ); 
         dwReturn["ARODESS"] = " ".PadRight(10 ); 
         dwReturn["AROCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["AROFGMGS"] = " ".PadRight(0 ); 
         dwReturn["AROFGMGI"] = " ".PadRight(0 ); 
         dwReturn["AROFGMGKG"] = " ".PadRight(0 ); 
         dwReturn["AROFLOTTE"] = " ".PadRight(0 ); 
         dwReturn["AROFAUF"] = " ".PadRight(0 ); 
         dwReturn["AROBRT"] = " ".PadRight(0 ); 
         dwReturn["AROGRLFM"] = " ".PadRight(0 ); 
         dwReturn["AROEVAR"] = " ".PadRight(4 ); 
         dwReturn["ARODTEXT1"] = " ".PadRight(50 ); 
         dwReturn["ARODTEXT2"] = " ".PadRight(50 ); 
         dwReturn["AROKUNDNA"] = " ".PadRight(8 ); 
         dwReturn["AROISTBDAT"] = " ".PadRight(0 ); 
         dwReturn["AROISTBZT"] = " ".PadRight(0 ); 
         dwReturn["AROISTEDAT"] = " ".PadRight(0 ); 
         dwReturn["AROISTEZT"] = " ".PadRight(0 ); 
         dwReturn["AROZTMM"] = " ".PadRight(0 ); 
         dwReturn["AROFILLER"] = " ".PadRight(37 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapARDO(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveARDO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryARDO(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapARDO(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertARDO(dwLocal, ITXDBVERSION);
            }
            UpdateARDO(dwLocal);
        }
        public void InsertARDO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ARDO(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryARDO(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ARDO WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ARDO  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ARDO";
            Return = Result;
            return Return;
        }
        public void DeleteARDO(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ARDO   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateARDO(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ARDO SET "
                    +"AROMANDANT= :AROMANDANT,"
                    +"AROAUFKRS= :AROAUFKRS,"
                    +"AROAUFLFD= :AROAUFLFD,"
                    +"AROAUFPOS= :AROAUFPOS,"
                    +"AROANSNR= :AROANSNR,"
                    +"AROABRNR= :AROABRNR,"
                    +"AROAENZL= :AROAENZL,"
                    +"AROAENB= :AROAENB,"
                    +"AROAEND= :AROAEND,"
                    +"ARONEUB= :ARONEUB,"
                    +"ARONEUD= :ARONEUD,"
                    +"AROAUFSTA= :AROAUFSTA,"
                    +"AROBDAT= :AROBDAT,"
                    +"AROBZT= :AROBZT,"
                    +"AROREFNR= :AROREFNR,"
                    +"AROPRIO= :AROPRIO,"
                    +"ARODOSYS1= :ARODOSYS1,"
                    +"ARODOEZT1= :ARODOEZT1,"
                    +"ARODOSYS2= :ARODOSYS2,"
                    +"ARODOEZT2= :ARODOEZT2,"
                    +"ARODOSYS3= :ARODOSYS3,"
                    +"ARODOEZT3= :ARODOEZT3,"
                    +"AROBHNR= :AROBHNR,"
                    +"AROFMGS= :AROFMGS,"
                    +"AROFMGI= :AROFMGI,"
                    +"AROWASMGI= :AROWASMGI,"
                    +"AROMTYP= :AROMTYP,"
                    +"AROMNRKRS= :AROMNRKRS,"
                    +"AROMLFDNR= :AROMLFDNR,"
                    +"AROMPOS= :AROMPOS,"
                    +"AROBDEMA= :AROBDEMA,"
                    +"AROAFOLGE= :AROAFOLGE,"
                    +"AROAGANG= :AROAGANG,"
                    +"ARODREZART= :ARODREZART,"
                    +"ARODREZNR= :ARODREZNR,"
                    +"ARODREZST= :ARODREZST,"
                    +"AROABRNR2= :AROABRNR2,"
                    +"AROART= :AROART,"
                    +"AROARTBEZ= :AROARTBEZ,"
                    +"AROFARBE= :AROFARBE,"
                    +"AROFARBEZ= :AROFARBEZ,"
                    +"ARODESS= :ARODESS,"
                    +"AROCOLORIT= :AROCOLORIT,"
                    +"AROFGMGS= :AROFGMGS,"
                    +"AROFGMGI= :AROFGMGI,"
                    +"AROFGMGKG= :AROFGMGKG,"
                    +"AROFLOTTE= :AROFLOTTE,"
                    +"AROFAUF= :AROFAUF,"
                    +"AROBRT= :AROBRT,"
                    +"AROGRLFM= :AROGRLFM,"
                    +"AROEVAR= :AROEVAR,"
                    +"ARODTEXT1= :ARODTEXT1,"
                    +"ARODTEXT2= :ARODTEXT2,"
                    +"AROKUNDNA= :AROKUNDNA,"
                    +"AROISTBDAT= :AROISTBDAT,"
                    +"AROISTBZT= :AROISTBZT,"
                    +"AROISTEDAT= :AROISTEDAT,"
                    +"AROISTEZT= :AROISTEZT,"
                    +"AROZTMM= :AROZTMM,"
                    +"AROFILLER= :AROFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AROMANDANT", OracleType.NVarChar).Value = dwData["AROMANDANT"].ToString(); 
          or1.Parameters.Add("AROAUFKRS", OracleType.NVarChar).Value = dwData["AROAUFKRS"].ToString(); 
          or1.Parameters.Add("AROAUFLFD", OracleType.NVarChar).Value = dwData["AROAUFLFD"].ToString(); 
          or1.Parameters.Add("AROAUFPOS", OracleType.NVarChar).Value = dwData["AROAUFPOS"].ToString(); 
          or1.Parameters.Add("AROANSNR", OracleType.NVarChar).Value = dwData["AROANSNR"].ToString(); 
          or1.Parameters.Add("AROABRNR", OracleType.NVarChar).Value = dwData["AROABRNR"].ToString(); 
          or1.Parameters.Add("AROAENZL", OracleType.NVarChar).Value = dwData["AROAENZL"].ToString(); 
          or1.Parameters.Add("AROAENB", OracleType.NVarChar).Value = dwData["AROAENB"].ToString(); 
          or1.Parameters.Add("AROAEND", OracleType.NVarChar).Value = dwData["AROAEND"].ToString(); 
          or1.Parameters.Add("ARONEUB", OracleType.NVarChar).Value = dwData["ARONEUB"].ToString(); 
          or1.Parameters.Add("ARONEUD", OracleType.NVarChar).Value = dwData["ARONEUD"].ToString(); 
          or1.Parameters.Add("AROAUFSTA", OracleType.NVarChar).Value = dwData["AROAUFSTA"].ToString(); 
          or1.Parameters.Add("AROBDAT", OracleType.NVarChar).Value = dwData["AROBDAT"].ToString(); 
          or1.Parameters.Add("AROBZT", OracleType.NVarChar).Value = dwData["AROBZT"].ToString(); 
          or1.Parameters.Add("AROREFNR", OracleType.NVarChar).Value = dwData["AROREFNR"].ToString(); 
          or1.Parameters.Add("AROPRIO", OracleType.NVarChar).Value = dwData["AROPRIO"].ToString(); 
          or1.Parameters.Add("ARODOSYS1", OracleType.NVarChar).Value = dwData["ARODOSYS1"].ToString(); 
          or1.Parameters.Add("ARODOEZT1", OracleType.NVarChar).Value = dwData["ARODOEZT1"].ToString(); 
          or1.Parameters.Add("ARODOSYS2", OracleType.NVarChar).Value = dwData["ARODOSYS2"].ToString(); 
          or1.Parameters.Add("ARODOEZT2", OracleType.NVarChar).Value = dwData["ARODOEZT2"].ToString(); 
          or1.Parameters.Add("ARODOSYS3", OracleType.NVarChar).Value = dwData["ARODOSYS3"].ToString(); 
          or1.Parameters.Add("ARODOEZT3", OracleType.NVarChar).Value = dwData["ARODOEZT3"].ToString(); 
          or1.Parameters.Add("AROBHNR", OracleType.NVarChar).Value = dwData["AROBHNR"].ToString(); 
          or1.Parameters.Add("AROFMGS", OracleType.NVarChar).Value = dwData["AROFMGS"].ToString(); 
          or1.Parameters.Add("AROFMGI", OracleType.NVarChar).Value = dwData["AROFMGI"].ToString(); 
          or1.Parameters.Add("AROWASMGI", OracleType.NVarChar).Value = dwData["AROWASMGI"].ToString(); 
          or1.Parameters.Add("AROMTYP", OracleType.NVarChar).Value = dwData["AROMTYP"].ToString(); 
          or1.Parameters.Add("AROMNRKRS", OracleType.NVarChar).Value = dwData["AROMNRKRS"].ToString(); 
          or1.Parameters.Add("AROMLFDNR", OracleType.NVarChar).Value = dwData["AROMLFDNR"].ToString(); 
          or1.Parameters.Add("AROMPOS", OracleType.NVarChar).Value = dwData["AROMPOS"].ToString(); 
          or1.Parameters.Add("AROBDEMA", OracleType.NVarChar).Value = dwData["AROBDEMA"].ToString(); 
          or1.Parameters.Add("AROAFOLGE", OracleType.NVarChar).Value = dwData["AROAFOLGE"].ToString(); 
          or1.Parameters.Add("AROAGANG", OracleType.NVarChar).Value = dwData["AROAGANG"].ToString(); 
          or1.Parameters.Add("ARODREZART", OracleType.NVarChar).Value = dwData["ARODREZART"].ToString(); 
          or1.Parameters.Add("ARODREZNR", OracleType.NVarChar).Value = dwData["ARODREZNR"].ToString(); 
          or1.Parameters.Add("ARODREZST", OracleType.NVarChar).Value = dwData["ARODREZST"].ToString(); 
          or1.Parameters.Add("AROABRNR2", OracleType.NVarChar).Value = dwData["AROABRNR2"].ToString(); 
          or1.Parameters.Add("AROART", OracleType.NVarChar).Value = dwData["AROART"].ToString(); 
          or1.Parameters.Add("AROARTBEZ", OracleType.NVarChar).Value = dwData["AROARTBEZ"].ToString(); 
          or1.Parameters.Add("AROFARBE", OracleType.NVarChar).Value = dwData["AROFARBE"].ToString(); 
          or1.Parameters.Add("AROFARBEZ", OracleType.NVarChar).Value = dwData["AROFARBEZ"].ToString(); 
          or1.Parameters.Add("ARODESS", OracleType.NVarChar).Value = dwData["ARODESS"].ToString(); 
          or1.Parameters.Add("AROCOLORIT", OracleType.NVarChar).Value = dwData["AROCOLORIT"].ToString(); 
          or1.Parameters.Add("AROFGMGS", OracleType.NVarChar).Value = dwData["AROFGMGS"].ToString(); 
          or1.Parameters.Add("AROFGMGI", OracleType.NVarChar).Value = dwData["AROFGMGI"].ToString(); 
          or1.Parameters.Add("AROFGMGKG", OracleType.NVarChar).Value = dwData["AROFGMGKG"].ToString(); 
          or1.Parameters.Add("AROFLOTTE", OracleType.NVarChar).Value = dwData["AROFLOTTE"].ToString(); 
          or1.Parameters.Add("AROFAUF", OracleType.NVarChar).Value = dwData["AROFAUF"].ToString(); 
          or1.Parameters.Add("AROBRT", OracleType.NVarChar).Value = dwData["AROBRT"].ToString(); 
          or1.Parameters.Add("AROGRLFM", OracleType.NVarChar).Value = dwData["AROGRLFM"].ToString(); 
          or1.Parameters.Add("AROEVAR", OracleType.NVarChar).Value = dwData["AROEVAR"].ToString(); 
          or1.Parameters.Add("ARODTEXT1", OracleType.NVarChar).Value = dwData["ARODTEXT1"].ToString(); 
          or1.Parameters.Add("ARODTEXT2", OracleType.NVarChar).Value = dwData["ARODTEXT2"].ToString(); 
          or1.Parameters.Add("AROKUNDNA", OracleType.NVarChar).Value = dwData["AROKUNDNA"].ToString(); 
          or1.Parameters.Add("AROISTBDAT", OracleType.NVarChar).Value = dwData["AROISTBDAT"].ToString(); 
          or1.Parameters.Add("AROISTBZT", OracleType.NVarChar).Value = dwData["AROISTBZT"].ToString(); 
          or1.Parameters.Add("AROISTEDAT", OracleType.NVarChar).Value = dwData["AROISTEDAT"].ToString(); 
          or1.Parameters.Add("AROISTEZT", OracleType.NVarChar).Value = dwData["AROISTEZT"].ToString(); 
          or1.Parameters.Add("AROZTMM", OracleType.NVarChar).Value = dwData["AROZTMM"].ToString(); 
          or1.Parameters.Add("AROFILLER", OracleType.NVarChar).Value = dwData["AROFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
